﻿using System;

using System.Collections.Generic;
using System.Text;

namespace UltiCoreLibrary
{
    public enum BasicGameType
    {
        GAME_PARTY = 1,
        GAME_40 = 2,
        GAME_4ACE = 3,
        GAME_ULTI = 4,
        GAME_BETLI = 5,
        GAME_20 = 6,
        GAME_DURCHMARS = 7,
        GAME_100 = 8,
        GAME_FAILED_ULTI = 9 
    }

    public class BasicGame: IComparable
    {
        override public string ToString()
        {
            string rval = "";
            if (hearts)
            {
                rval += "Hearts ";
            }
            if (open)
            {
                rval += "Open";
            }
            if (unBid)
            {
                rval += "Unbid ";
            }
            rval += name;
            return rval;
        }

        public static LinkedList<BasicGame> colorlessGames = new LinkedList<BasicGame>();

        public static LinkedList<BasicGame> unBidGames = new LinkedList<BasicGame>();

        static BasicGame()
        {
            colorlessGames.AddLast(new BasicGame(BasicGameType.GAME_BETLI, false, false, false));
            colorlessGames.AddLast(new BasicGame(BasicGameType.GAME_DURCHMARS, false, false, false));
            colorlessGames.AddLast(new BasicGame(BasicGameType.GAME_BETLI, true, false, false));
            colorlessGames.AddLast(new BasicGame(BasicGameType.GAME_DURCHMARS, true, false, false));
            colorlessGames.AddLast(new BasicGame(BasicGameType.GAME_DURCHMARS, false, true, false));
            colorlessGames.AddLast(new BasicGame(BasicGameType.GAME_BETLI, true, true, false));
            colorlessGames.AddLast(new BasicGame(BasicGameType.GAME_DURCHMARS, true, true, false));

            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_100, false, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_100, true, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_4ACE, false, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_4ACE, true, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_DURCHMARS, false, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_DURCHMARS, true, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_ULTI, false, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_ULTI, true, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_FAILED_ULTI, false, false, true));
            unBidGames.AddLast(new BasicGame(BasicGameType.GAME_FAILED_ULTI, true, false, true));
        }

        private string name;

        public string Name
        {
            get { return name; }
            // set { name = value; }
        }


        private int value;

        public int Value
        {
            get {
                int tmpvalue = this.value;
                if (this.open)
                {
                    tmpvalue *= 2;
                }
                if (this.hearts)
                {
                    tmpvalue *= 2;
                }
                if (this.unBid)
                {
                    tmpvalue /= 2;
                }
                return tmpvalue;
            }
            // set { this.value = value; }
        }

        private Boolean success = false;

        public Boolean Success
        {
            get { return success; }
            set { success = value; }
        }
        private Boolean hearts = false;

        public Boolean Hearts
        {
            get { return hearts; }
            set { hearts = value; }
        }
        private Boolean open = false;

        public Boolean Open
        {
            get { return open; }
            set { open = value; }
        }

        private BasicGameType id;

        public BasicGameType Game
        {
            get { return id; }
            set { id = value; }
        }

        private Boolean unBid;

        public Boolean UnBid
        {
            get { return unBid; }
            // set { unBid = value; }
        }

        public BasicGame(BasicGameType game, Boolean hearts, Boolean open, Boolean unBid)
        {
            this.id = game;
            this.hearts = hearts;
            this.open = open;
            this.unBid = unBid;

            switch (id)
            {
                case BasicGameType.GAME_20:
                    value = 6;
                    name = "20-100";
                    break;
                case BasicGameType.GAME_40:
                    value = 4;
                    name = "40-100";
                    break;
                case BasicGameType.GAME_4ACE:
                    value = 4;
                    name = "4 Ace";
                    break;
                case BasicGameType.GAME_BETLI:
                    value = 5;
                    name = "Betli";
                    break;
                case BasicGameType.GAME_DURCHMARS:
                    value = 7;
                    name = "Durchmars";
                    break;
                case BasicGameType.GAME_PARTY:
                    value = 1;
                    name = "Party";
                    break;
                case BasicGameType.GAME_ULTI:
                    value = 4;
                    name = "Ulti";
                    break;
                case BasicGameType.GAME_100:
                    value = 4;
                    name = "100";
                    break;
                case BasicGameType.GAME_FAILED_ULTI:
                    value = -4;
                    name = "Failed Ulti";
                    break;
            }
            /*
            if (this.open)
            {
                value *= 2;
            }
            if (this.hearts)
            {
                value *= 2;
            }
            if (this.unBid)
            {
                value /= 2;
            }
             */
        }


        #region IComparable Members

        public int CompareTo(object obj)
        {
            // throw new Exception("The method or operation is not implemented.");

            return (
                id == ((BasicGame)obj).id &&
                open == ((BasicGame)obj).open &&
                hearts == ((BasicGame)obj).hearts &&
                unBid == ((BasicGame)obj).unBid
                ) ? 0 : -1;
        }

        #endregion
    }
}
